home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / ctrltest / paredit2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  3.4 KB  |  106 lines

  1. // paredit2.cpp : code needed to export CParsedEdit as a WndClass
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1999 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "ctrltest.h"
  15.  
  16. #include "paredit.h"
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // The C++ class CParsedEdit can be made visible to the dialog manager
  20. //   by registering a window class for it
  21. // The C++ class 'CParsedEditExported' is used to implement the
  22. //   creation and destruction of a C++ object as if it were just
  23. //   a normal Windows control.
  24. // In order to hook in the class creation we must provide a special
  25. //   WndProc to create the C++ object and override the PostNcDestroy
  26. //   message to destroy it
  27.  
  28. class CParsedEditExported : public CParsedEdit      // WNDCLASS exported class
  29. {
  30. public:
  31.     CParsedEditExported() { };
  32.     BOOL RegisterControlClass();
  33.  
  34. // Implementation: (all is implementation since the public interface of
  35. //    this class is identical to CParsedEdit)
  36. protected:
  37.     virtual void PostNcDestroy();
  38.     static LRESULT CALLBACK EXPORT WndProcHook(HWND, UINT, WPARAM, LPARAM);
  39.     static WNDPROC lpfnSuperEdit;
  40.  
  41.     friend class CParsedEdit;       // for RegisterControlClass
  42.  
  43.     //{{AFX_MSG(CParsedEditExported)
  44.     //}}AFX_MSG
  45.     DECLARE_MESSAGE_MAP();
  46. };
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // Special create hooks
  50.  
  51. LRESULT CALLBACK EXPORT
  52. CParsedEditExported::WndProcHook(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  53. {
  54.     // create new item and attach it
  55.     CParsedEditExported* pEdit = new CParsedEditExported();
  56.     pEdit->Attach(hWnd);
  57.  
  58.     // set up wndproc to AFX one, and call it
  59.     pEdit->m_pfnSuper = CParsedEditExported::lpfnSuperEdit;
  60.     ::SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)AfxWndProc);
  61.  
  62.     // then call it for this first message
  63.     return ::CallWindowProc(AfxWndProc, hWnd, msg, wParam, lParam);
  64. }
  65.  
  66. BEGIN_MESSAGE_MAP(CParsedEditExported, CParsedEdit)
  67.     //{{AFX_MSG_MAP(CParsedEditExported)
  68.     //}}AFX_MSG_MAP
  69. END_MESSAGE_MAP()
  70.  
  71. void CParsedEditExported::PostNcDestroy()
  72. {
  73.     // needed to clean up the C++ CWnd object
  74.     delete this;
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // Routine to register the class
  79.  
  80. WNDPROC CParsedEditExported::lpfnSuperEdit = NULL;
  81.  
  82. BOOL CParsedEdit::RegisterControlClass()
  83. {
  84.     WNDCLASS wcls;
  85.  
  86.     // check to see if class already registered
  87.     static const TCHAR szClass[] = _T("paredit");
  88.     if (::GetClassInfo(AfxGetInstanceHandle(), szClass, &wcls))
  89.     {
  90.         // name already registered - ok if it was us
  91.         return (wcls.lpfnWndProc == (WNDPROC)CParsedEditExported::WndProcHook);
  92.     }
  93.  
  94.     // Use standard "edit" control as a template.
  95.     VERIFY(::GetClassInfo(NULL, _T("edit"), &wcls));
  96.     CParsedEditExported::lpfnSuperEdit = wcls.lpfnWndProc;
  97.  
  98.     // set new values
  99.     wcls.lpfnWndProc = CParsedEditExported::WndProcHook;
  100.     wcls.hInstance = AfxGetInstanceHandle();
  101.     wcls.lpszClassName = szClass;
  102.     return (RegisterClass(&wcls) != 0);
  103. }
  104.  
  105. /////////////////////////////////////////////////////////////////////////////
  106.